package com.zhwmall.product.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhwmall.common.entity.product.BrandEntity;
import com.zhwmall.common.entity.product.CategoryBrandRelationEntity;
import com.zhwmall.common.entity.product.CategoryEntity;
import com.zhwmall.product.dao.BrandDao;
import com.zhwmall.product.dao.CategoryBrandRelationDao;
import com.zhwmall.product.dao.CategoryDao;
import com.zhwmall.product.service.CategoryBrandRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("categoryBrandRelationService")
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationDao, CategoryBrandRelationEntity> implements CategoryBrandRelationService {


    @Autowired
    private BrandDao brandDao;

    @Autowired
    private CategoryDao categoryDao;

    @Override
    public void saveIdAndName(CategoryBrandRelationEntity categoryBrandRelation) {
        BrandEntity brandEntity = brandDao.selectById(categoryBrandRelation.getBrandId());

        CategoryEntity categoryEntity = categoryDao.selectById(categoryBrandRelation.getCatelogId());

        CategoryBrandRelationEntity build = CategoryBrandRelationEntity.builder()
                .brandId(brandEntity.getBrandId())
                .brandName(brandEntity.getName())
                .catelogId(categoryEntity.getCatId())
                .catelogName(categoryEntity.getName()).build();

        baseMapper.insert(build);
    }

}